using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using MVCWeekOne.Models;
using System.Text.Json;

namespace MVCWeekOne.Controllers
{
    /// <summary>
    /// 智能车间生产管控大屏控制器
    /// </summary>
    [Route("[controller]")]
    public class DashboardController : Controller
    {
        private readonly HttpClient _httpClient;
        private readonly ApiSettings _apiSettings;

        public DashboardController(IHttpClientFactory httpClientFactory, IOptions<ApiSettings> apiSettings)
        {
            _httpClient = httpClientFactory.CreateClient();
            _apiSettings = apiSettings.Value;
            
            // 配置HttpClient超时
            _httpClient.Timeout = TimeSpan.FromSeconds(_apiSettings.TimeoutSeconds);
        }

        /// <summary>
        /// 智能车间生产管控大屏首页
        /// </summary>
        /// <returns></returns>
        [Route("Index")]
        [Route("")]
        public IActionResult Index()
        {
            ViewData["Title"] = "智能车间生产管控大屏";
            // 传递API配置到前端
            ViewBag.ReadApiUrl = _apiSettings.ReadApiUrl;
            ViewBag.WriteApiUrl = _apiSettings.WriteApiUrl;
            return View();
        }

        /// <summary>
        /// 获取实时生产数据
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("GetRealTimeData")]
        public async Task<IActionResult> GetRealTimeData()
        {
            try
            {
                // 调用后端Dashboard API获取综合数据
                var response = await _httpClient.GetAsync($"{_apiSettings.ReadApiUrl}/Dashboard/CumulativeData");
                
                if (response.IsSuccessStatusCode)
                {
                    var jsonContent = await response.Content.ReadAsStringAsync();
                    var apiResult = JsonSerializer.Deserialize<ApiResult<CumulativeDataDto>>(jsonContent);
                    
                    if (apiResult?.Code == 200 && apiResult.Data != null)
                    {
                        var cumulativeData = apiResult.Data;
                        
                        // 获取不良品率数据
                        var defectiveResponse = await _httpClient.GetAsync($"{_apiSettings.ReadApiUrl}/Dashboard/DefectiveRate?days=7");
                        decimal defectiveRate = 0;
                        if (defectiveResponse.IsSuccessStatusCode)
                        {
                            var defectiveJson = await defectiveResponse.Content.ReadAsStringAsync();
                            var defectiveResult = JsonSerializer.Deserialize<ApiResult<DefectiveRateDto>>(defectiveJson);
                            if (defectiveResult?.Code == 200)
                            {
                                defectiveRate = defectiveResult.Data.DefectiveRate;
                            }
                        }

                        // 构建返回数据
                        var data = new
                        {
                            // 设备利用率 - 基于良品率计算
                            equipmentUtilization = Math.Max(85.0, 100 - (double)defectiveRate),
                            // 日产量 - 使用累计合格数据
                            dailyOutput = cumulativeData.CumulativeQualifiedData,
                            // 良品率 - 计算合格率
                            qualityRate = cumulativeData.CumulativeUnitsData > 0 ? 
                                Math.Round((double)cumulativeData.CumulativeQualifiedData / cumulativeData.CumulativeUnitsData * 100, 1) : 0,
                            // 在线人数 - 模拟数据，可后续从人员系统获取
                            onlinePersonnel = 25,
                            // 生产线状态 - 基于数据情况模拟
                            productionLines = new
                            {
                                total = 8,
                                running = cumulativeData.CumulativeUnitsData > 1000 ? 8 : 7,
                                maintenance = cumulativeData.CumulativeUnitsData > 1000 ? 0 : 1,
                                fault = 0
                            },
                            // 设备状态
                            equipment = new
                            {
                                total = 45,
                                running = Math.Max(40, 45 - (int)(defectiveRate / 2)),
                                maintenance = Math.Min(3, (int)(defectiveRate / 2)),
                                fault = defectiveRate > 5 ? 2 : 0
                            },
                            // 不良率
                            defectRate = Math.Round((double)defectiveRate, 1),
                            // 工作效率 - 基于计划完成情况
                            efficiency = cumulativeData.ProductionPlanData > 0 ? 
                                Math.Round((double)cumulativeData.CumulativeUnitsData / cumulativeData.ProductionPlanData * 100, 1) : 95.0,
                            timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
                        };

                        return Json(data);
                    }
                }
                
                // 如果API调用失败，返回默认数据
                return Json(GetDefaultRealTimeData());
            }
            catch (Exception)
            {
                // 出错时返回默认数据
                return Json(GetDefaultRealTimeData());
            }
        }

        /// <summary>
        /// 获取生产统计数据
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("GetProductionStatistics")]
        public async Task<IActionResult> GetProductionStatistics()
        {
            try
            {
                var response = await _httpClient.GetAsync($"{_apiSettings.ReadApiUrl}/ProductionStatistics/page?index=1&size=50");
                
                if (response.IsSuccessStatusCode)
                {
                    var jsonContent = await response.Content.ReadAsStringAsync();
                    var apiResult = JsonSerializer.Deserialize<ApiResult<ProductionStatisticsPageResult>>(jsonContent);
                    
                    if (apiResult?.Code == 200 && apiResult.Data?.Data != null)
                    {
                        var statistics = apiResult.Data.Data;
                        
                        // 按日期分组统计
                        var dailyData = statistics
                            .Where(s => s.ReportingDate >= DateTime.Now.AddDays(-7))
                            .GroupBy(s => s.ReportingDate.ToString("MM-dd"))
                            .Select(g => new
                            {
                                date = g.Key,
                                productName = g.First().ProductName,
                                quantity = g.Sum(s => s.Quantity),
                                planCount = g.Sum(s => s.WorkOrderPlanCount ?? 0)
                            })
                            .OrderBy(x => x.date)
                            .Take(5)
                            .ToList();

                        return Json(dailyData);
                    }
                }
                
                return Json(new List<object>());
            }
            catch (Exception)
            {
                return Json(new List<object>());
            }
        }

        /// <summary>
        /// 获取不良品分布Top5
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("GetDefectiveTop5")]
        public async Task<IActionResult> GetDefectiveTop5()
        {
            try
            {
                var response = await _httpClient.GetAsync($"{_apiSettings.ReadApiUrl}/Dashboard/DefectiveItemRank?days=30&top=5");
                
                if (response.IsSuccessStatusCode)
                {
                    var jsonContent = await response.Content.ReadAsStringAsync();
                    var apiResult = JsonSerializer.Deserialize<ApiResult<List<DefectiveItemRankDto>>>(jsonContent);
                    
                    if (apiResult?.Code == 200 && apiResult.Data != null)
                    {
                        var topDefectives = apiResult.Data.Select((item, index) => new
                        {
                            rank = index + 1,
                            name = item.DefectiveItemName,
                            quantity = item.TotalQuantity,
                            percentage = Math.Round(item.Percentage, 1)
                        }).ToList();

                        return Json(topDefectives);
                    }
                }
                
                return Json(new List<object>());
            }
            catch (Exception)
            {
                return Json(new List<object>());
            }
        }

        /// <summary>
        /// 获取工单执行效率Top5
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("GetWorkOrderEfficiencyTop5")]
        public async Task<IActionResult> GetWorkOrderEfficiencyTop5()
        {
            try
            {
                var response = await _httpClient.GetAsync($"{_apiSettings.ReadApiUrl}/WorkOrder/comprehensive?index=1&size=20");
                
                if (response.IsSuccessStatusCode)
                {
                    var jsonContent = await response.Content.ReadAsStringAsync();
                    var apiResult = JsonSerializer.Deserialize<ApiResult<WorkOrderComprehensivePageResult>>(jsonContent);
                    
                    if (apiResult?.Code == 200 && apiResult.Data?.Data != null)
                    {
                        var workOrders = apiResult.Data.Data
                            .Where(wo => wo.WorkOrder?.PlannedQuantity > 0)
                            .Select(wo => new
                            {
                                workOrderCode = wo.WorkOrder.Code,
                                productName = wo.ProductInfo?.ProductName ?? "未知产品",
                                efficiency = wo.WorkOrder.PlannedQuantity > 0 ? 
                                    Math.Round((decimal)((double)(wo.WorkOrder.ActualQuantity ?? 0) / wo.WorkOrder.PlannedQuantity * 100), 1) : 0,
                                plannedQty = wo.WorkOrder.PlannedQuantity,
                                actualQty = wo.WorkOrder.ActualQuantity ?? 0
                            })
                            .OrderByDescending(x => x.efficiency)
                            .Take(5)
                            .Select((item, index) => new
                            {
                                rank = index + 1,
                                workOrderCode = item.workOrderCode,
                                productName = item.productName,
                                efficiency = item.efficiency
                            })
                            .ToList();

                        return Json(workOrders);
                    }
                }
                
                return Json(new List<object>());
            }
            catch (Exception)
            {
                return Json(new List<object>());
            }
        }

        /// <summary>
        /// 获取生产趋势数据
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("GetTrendData")]
        public async Task<IActionResult> GetTrendData()
        {
            try
            {
                var response = await _httpClient.GetAsync($"{_apiSettings.ReadApiUrl}/ProductionStatistics/page?index=1&size=100");
                
                if (response.IsSuccessStatusCode)
                {
                    var jsonContent = await response.Content.ReadAsStringAsync();
                    var apiResult = JsonSerializer.Deserialize<ApiResult<ProductionStatisticsPageResult>>(jsonContent);
                    
                    if (apiResult?.Code == 200 && apiResult.Data?.Data != null)
                    {
                        // 按日期分组获取最近7天的数据
                        var trendData = apiResult.Data.Data
                            .Where(s => s.ReportingDate >= DateTime.Now.AddDays(-7))
                            .GroupBy(s => s.ReportingDate.ToString("MM-dd"))
                            .Select(g => new
                            {
                                date = g.Key,
                                output = g.Sum(s => s.Quantity),
                                quality = g.Average(s => s.WorkOrderPlanCount > 0 ? 
                                    (double)s.Quantity / s.WorkOrderPlanCount * 100 : 95.0)
                            })
                            .OrderBy(x => x.date)
                            .ToList();

                        var data = new
                        {
                            dates = trendData.Select(x => x.date).ToList(),
                            output = trendData.Select(x => x.output).ToList(),
                            quality = trendData.Select(x => Math.Round((decimal)x.quality, 1)).ToList()
                        };

                        return Json(data);
                    }
                }
                
                // 返回默认趋势数据
                return Json(GetDefaultTrendData());
            }
            catch (Exception)
            {
                return Json(GetDefaultTrendData());
            }
        }

        #region 私有方法

        /// <summary>
        /// 获取默认实时数据（API调用失败时使用）
        /// </summary>
        private object GetDefaultRealTimeData()
        {
            return new
            {
                equipmentUtilization = 95.0,
                dailyOutput = 1200,
                qualityRate = 96.5,
                onlinePersonnel = 25,
                productionLines = new { total = 8, running = 7, maintenance = 1, fault = 0 },
                equipment = new { total = 45, running = 42, maintenance = 2, fault = 1 },
                defectRate = 3.5,
                efficiency = 92.0,
                timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
            };
        }

        /// <summary>
        /// 获取默认趋势数据（API调用失败时使用）
        /// </summary>
        private object GetDefaultTrendData()
        {
            var dates = new List<string>();
            var output = new List<int>();
            var quality = new List<double>();

            for (int i = 6; i >= 0; i--)
            {
                dates.Add(DateTime.Now.AddDays(-i).ToString("MM-dd"));
                output.Add(180 + new Random().Next(-20, 30));
                quality.Add(Math.Round(94.0 + new Random().NextDouble() * 4, 1));
            }

            return new { dates, output, quality };
        }

        #endregion

        #region Dashboard API Methods

        /// <summary>
        /// 获取不良品率统计
        /// </summary>
        [HttpGet]
        [Route("GetDefectiveRate")]
        public async Task<IActionResult> GetDefectiveRate(int days = 7)
        {
            try
            {
                var response = await _httpClient.GetAsync($"{_apiSettings.ReadApiUrl}/Dashboard/GetDefectiveRate?days={days}");
                
                if (response.IsSuccessStatusCode)
                {
                    var jsonContent = await response.Content.ReadAsStringAsync();
                    var apiResult = JsonSerializer.Deserialize<ApiResult<DefectiveRateDto>>(jsonContent);
                    
                    if (apiResult?.Code == 200)
                    {
                        return Json(new { success = true, data = apiResult.Data });
                    }
                    
                    return Json(new { success = false, message = apiResult?.Msg ?? "API调用失败" });
                }
                
                return Json(new { success = false, message = "API调用失败" });
            }
            catch (Exception ex)
            {
                return Json(new { success = false, message = ex.Message });
            }
        }

        /// <summary>
        /// 获取生产统计汇总
        /// </summary>
        [HttpGet]
        [Route("GetProductionSummary")]
        public async Task<IActionResult> GetProductionSummary(int days = 30)
        {
            try
            {
                var response = await _httpClient.GetAsync($"{_apiSettings.ReadApiUrl}/Dashboard/GetProductionSummary?days={days}");
                
                if (response.IsSuccessStatusCode)
                {
                    var jsonContent = await response.Content.ReadAsStringAsync();
                    var apiResult = JsonSerializer.Deserialize<ApiResult<ProductionSummaryDto>>(jsonContent);
                    
                    if (apiResult?.Code == 200)
                    {
                        return Json(new { success = true, data = apiResult.Data });
                    }
                    
                    return Json(new { success = false, message = apiResult?.Msg ?? "API调用失败" });
                }
                
                return Json(new { success = false, message = "API调用失败" });
            }
            catch (Exception ex)
            {
                return Json(new { success = false, message = ex.Message });
            }
        }

        /// <summary>
        /// 获取员工绩效Top5
        /// </summary>
        [HttpGet]
        [Route("GetEmployeePerformance")]
        public async Task<IActionResult> GetEmployeePerformance(int days = 30)
        {
            try
            {
                var response = await _httpClient.GetAsync($"{_apiSettings.ReadApiUrl}/Dashboard/GetEmployeePerformance?days={days}");
                
                if (response.IsSuccessStatusCode)
                {
                    var jsonContent = await response.Content.ReadAsStringAsync();
                    var apiResult = JsonSerializer.Deserialize<ApiResult<List<EmployeePerformanceDto>>>(jsonContent);
                    
                    if (apiResult?.Code == 200)
                    {
                        return Json(new { success = true, data = apiResult.Data });
                    }
                    
                    return Json(new { success = false, message = apiResult?.Msg ?? "API调用失败" });
                }
                
                return Json(new { success = false, message = "API调用失败" });
            }
            catch (Exception ex)
            {
                return Json(new { success = false, message = ex.Message });
            }
        }

        /// <summary>
        /// 获取日生产明细
        /// </summary>
        [HttpGet]
        [Route("GetDailyProduction")]
        public async Task<IActionResult> GetDailyProduction(int days = 7)
        {
            try
            {
                var response = await _httpClient.GetAsync($"{_apiSettings.ReadApiUrl}/Dashboard/GetDailyProduction?days={days}");
                
                if (response.IsSuccessStatusCode)
                {
                    var jsonContent = await response.Content.ReadAsStringAsync();
                    var apiResult = JsonSerializer.Deserialize<ApiResult<List<DailyProductionDto>>>(jsonContent);
                    
                    if (apiResult?.Code == 200)
                    {
                        return Json(new { success = true, data = apiResult.Data });
                    }
                    
                    return Json(new { success = false, message = apiResult?.Msg ?? "API调用失败" });
                }
                
                return Json(new { success = false, message = "API调用失败" });
            }
            catch (Exception ex)
            {
                return Json(new { success = false, message = ex.Message });
            }
        }

        /// <summary>
        /// 获取工序计划排名
        /// </summary>
        [HttpGet]
        [Route("GetProcessPlanRank")]
        public async Task<IActionResult> GetProcessPlanRank(int days = 30)
        {
            try
            {
                var response = await _httpClient.GetAsync($"{_apiSettings.ReadApiUrl}/Dashboard/GetProcessPlanRank?days={days}");
                
                if (response.IsSuccessStatusCode)
                {
                    var jsonContent = await response.Content.ReadAsStringAsync();
                    var apiResult = JsonSerializer.Deserialize<ApiResult<List<ProcessPlanRankDto>>>(jsonContent);
                    
                    if (apiResult?.Code == 200)
                    {
                        return Json(new { success = true, data = apiResult.Data });
                    }
                    
                    return Json(new { success = false, message = apiResult?.Msg ?? "API调用失败" });
                }
                
                return Json(new { success = false, message = "API调用失败" });
            }
            catch (Exception ex)
            {
                return Json(new { success = false, message = ex.Message });
            }
        }

        /// <summary>
        /// 获取工序报工排名
        /// </summary>
        [HttpGet]
        [Route("GetProcessReportRank")]
        public async Task<IActionResult> GetProcessReportRank(int days = 30)
        {
            try
            {
                var response = await _httpClient.GetAsync($"{_apiSettings.ReadApiUrl}/Dashboard/GetProcessReportRank?days={days}");
                
                if (response.IsSuccessStatusCode)
                {
                    var jsonContent = await response.Content.ReadAsStringAsync();
                    var apiResult = JsonSerializer.Deserialize<ApiResult<List<ProcessReportRankDto>>>(jsonContent);
                    
                    if (apiResult?.Code == 200)
                    {
                        return Json(new { success = true, data = apiResult.Data });
                    }
                    
                    return Json(new { success = false, message = apiResult?.Msg ?? "API调用失败" });
                }
                
                return Json(new { success = false, message = "API调用失败" });
            }
            catch (Exception ex)
            {
                return Json(new { success = false, message = ex.Message });
            }
        }

        /// <summary>
        /// 获取销售订单统计
        /// </summary>
        [HttpGet]
        [Route("GetSalesOrderSummary")]
        public async Task<IActionResult> GetSalesOrderSummary(int days = 30)
        {
            try
            {
                var response = await _httpClient.GetAsync($"{_apiSettings.ReadApiUrl}/Dashboard/GetSalesOrderSummary?days={days}");
                
                if (response.IsSuccessStatusCode)
                {
                    var jsonContent = await response.Content.ReadAsStringAsync();
                    var apiResult = JsonSerializer.Deserialize<ApiResult<SalesOrderSummaryDto>>(jsonContent);
                    
                    if (apiResult?.Code == 200)
                    {
                        return Json(new { success = true, data = apiResult.Data });
                    }
                    
                    return Json(new { success = false, message = apiResult?.Msg ?? "API调用失败" });
                }
                
                return Json(new { success = false, message = "API调用失败" });
            }
            catch (Exception ex)
            {
                return Json(new { success = false, message = ex.Message });
            }
        }

        /// <summary>
        /// 获取不良品分布排名
        /// </summary>
        [HttpGet]
        [Route("GetDefectiveItemRank")]
        public async Task<IActionResult> GetDefectiveItemRank(int days = 30, int top = 5)
        {
            try
            {
                var response = await _httpClient.GetAsync($"{_apiSettings.ReadApiUrl}/Dashboard/GetDefectiveItemRank?days={days}&top={top}");
                
                if (response.IsSuccessStatusCode)
                {
                    var jsonContent = await response.Content.ReadAsStringAsync();
                    var apiResult = JsonSerializer.Deserialize<ApiResult<List<DefectiveItemRankDto>>>(jsonContent);
                    
                    if (apiResult?.Code == 200)
                    {
                        return Json(new { success = true, data = apiResult.Data });
                    }
                    
                    return Json(new { success = false, message = apiResult?.Msg ?? "API调用失败" });
                }
                
                return Json(new { success = false, message = "API调用失败" });
            }
            catch (Exception ex)
            {
                return Json(new { success = false, message = ex.Message });
            }
        }

        /// <summary>
        /// 获取累计数据
        /// </summary>
        [HttpGet]
        [Route("GetCumulativeData")]
        public async Task<IActionResult> GetCumulativeData()
        {
            try
            {
                var response = await _httpClient.GetAsync($"{_apiSettings.ReadApiUrl}/Dashboard/GetCumulativeData");
                
                if (response.IsSuccessStatusCode)
                {
                    var jsonContent = await response.Content.ReadAsStringAsync();
                    var apiResult = JsonSerializer.Deserialize<ApiResult<CumulativeDataDto>>(jsonContent);
                    
                    if (apiResult?.Code == 200)
                    {
                        return Json(new { success = true, data = apiResult.Data });
                    }
                    
                    return Json(new { success = false, message = apiResult?.Msg ?? "API调用失败" });
                }
                
                return Json(new { success = false, message = "API调用失败" });
            }
            catch (Exception ex)
            {
                return Json(new { success = false, message = ex.Message });
            }
        }

        #endregion
    }

    #region DTO类定义

    /// <summary>
    /// 不良品率DTO
    /// </summary>
    public class DefectiveRateDto
    {
        /// <summary>
        /// 总不良品数
        /// </summary>
        public int TotalDefective { get; set; }

        /// <summary>
        /// 总生产数
        /// </summary>
        public int TotalProduced { get; set; }

        /// <summary>
        /// 不良品率（百分比）
        /// </summary>
        public decimal DefectiveRate { get; set; }

        /// <summary>
        /// 日期范围
        /// </summary>
        public string DateRange { get; set; }
    }

    /// <summary>
    /// 不良品项排名DTO
    /// </summary>
    public class DefectiveItemRankDto
    {
        /// <summary>
        /// 不良品项编号
        /// </summary>
        public string DefectiveItemCode { get; set; }

        /// <summary>
        /// 不良品项名称
        /// </summary>
        public string DefectiveItemName { get; set; }

        /// <summary>
        /// 总数量
        /// </summary>
        public int TotalQuantity { get; set; }

        /// <summary>
        /// 占比（百分比）
        /// </summary>
        public decimal Percentage { get; set; }

        /// <summary>
        /// 平均占比
        /// </summary>
        public decimal AvgPercentage { get; set; }
    }

    /// <summary>
    /// 员工绩效DTO
    /// </summary>
    public class EmployeePerformanceDto
    {
        /// <summary>
        /// 员工姓名
        /// </summary>
        public string EmployeeName { get; set; }

        /// <summary>
        /// 总良品数量
        /// </summary>
        public int TotalGoodQuantity { get; set; }

        /// <summary>
        /// 总工作时长（分钟）
        /// </summary>
        public int TotalWorkTime { get; set; }

        /// <summary>
        /// 报工次数
        /// </summary>
        public int ReportCount { get; set; }

        /// <summary>
        /// 效率分数
        /// </summary>
        public decimal EfficiencyScore { get; set; }
    }

    /// <summary>
    /// 生产汇总DTO
    /// </summary>
    public class ProductionSummaryDto
    {
        /// <summary>
        /// 总良品数量
        /// </summary>
        public int TotalGoodQuantity { get; set; }

        /// <summary>
        /// 总不良品数量
        /// </summary>
        public int TotalBadQuantity { get; set; }

        /// <summary>
        /// 良品率
        /// </summary>
        public decimal GoodRate { get; set; }

        /// <summary>
        /// 总工单数
        /// </summary>
        public int TotalWorkOrders { get; set; }
    }

    /// <summary>
    /// 日生产明细DTO
    /// </summary>
    public class DailyProductionDto
    {
        /// <summary>
        /// 生产日期
        /// </summary>
        public DateTime ProductionDate { get; set; }

        /// <summary>
        /// 产品名称
        /// </summary>
        public string ProductName { get; set; }

        /// <summary>
        /// 计划数量
        /// </summary>
        public int PlannedQuantity { get; set; }

        /// <summary>
        /// 良品数量
        /// </summary>
        public int GoodQuantity { get; set; }

        /// <summary>
        /// 不良品数量
        /// </summary>
        public int BadQuantity { get; set; }

        /// <summary>
        /// 完成率
        /// </summary>
        public decimal CompletionRate { get; set; }
    }

    /// <summary>
    /// 工序计划排名DTO
    /// </summary>
    public class ProcessPlanRankDto
    {
        /// <summary>
        /// 工序名称
        /// </summary>
        public string ProcessName { get; set; }

        /// <summary>
        /// 总计划数量
        /// </summary>
        public int TotalPlannedQuantity { get; set; }

        /// <summary>
        /// 工序数量
        /// </summary>
        public int ProcessCount { get; set; }
    }

    /// <summary>
    /// 工序报工排名DTO
    /// </summary>
    public class ProcessReportRankDto
    {
        /// <summary>
        /// 工序名称
        /// </summary>
        public string ProcessName { get; set; }

        /// <summary>
        /// 总报工数量
        /// </summary>
        public int TotalReportedQuantity { get; set; }

        /// <summary>
        /// 报工次数
        /// </summary>
        public int ReportCount { get; set; }
    }

    /// <summary>
    /// 销售订单汇总DTO
    /// </summary>
    public class SalesOrderSummaryDto
    {
        /// <summary>
        /// 总订单数
        /// </summary>
        public int TotalOrders { get; set; }

        /// <summary>
        /// 总产品数
        /// </summary>
        public int TotalProducts { get; set; }

        /// <summary>
        /// 订单完成率
        /// </summary>
        public decimal OrderCompletionRate { get; set; }
    }

    /// <summary>
    /// 累计数据DTO
    /// </summary>
    public class CumulativeDataDto
    {
        /// <summary>
        /// 累计单台数据
        /// </summary>
        public int CumulativeUnitsData { get; set; }

        /// <summary>
        /// 生产计划数据
        /// </summary>
        public int ProductionPlanData { get; set; }

        /// <summary>
        /// 累计合格数据
        /// </summary>
        public int CumulativeQualifiedData { get; set; }

        /// <summary>
        /// 累计不合格数据
        /// </summary>
        public int CumulativeUnqualifiedData { get; set; }
    }

    #endregion
} 